package operation;

import book.Book;
import book.BookList;

import java.util.Scanner;

public class Del implements IOPer {
    @Override
    public void work(BookList bookList) {
        int i = 0;
        System.out.println("输入你要删除的图书");
        Scanner scanner = new Scanner(System.in);
        String name = scanner.nextLine();
        int sz = bookList.getUsersize();
        for (;i < sz; i++) {
            Book book1 = bookList.getBook(i);
            if (book1.getName().equals(name)) {
                break;
            }
        }
        if (i == sz) {
            System.out.println("没有找到");
        }
        for (; i < sz-1; i++) {
            Book book2 = bookList.getBook(i+1);
            bookList.setBooks(i,book2);
        }
        bookList.setBooks(i,null);
        bookList.setUsersize(sz-1);
    }
}
